package com.ruoyi.web.controller.biz;

import com.ruoyi.common.constant.BsSysConfigConstants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.Result;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.vo.BsSysConfigVO;
import com.ruoyi.system.service.ISysDictDataService;
import com.ruoyi.system.service.impl.BsSysConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 涉旅企业管理
 *
 * @author ruoyi
 * @date 2023-10-29
 */
@Validated
@RequiredArgsConstructor
@RestController
@Api(tags = "WEB端-系统配置")
@RequestMapping("/bs/sysConfig")
public class BsSysConfigController extends BaseController {

    @Resource
    private ISysDictDataService dictDataService;
    @Resource
    private BsSysConfigService bsSysConfigService;

    @ApiOperation(value = "整理风格-配置查询", tags = {"系统配置"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "分页参数：第几页"),
            @ApiImplicitParam(name = "pageSize", value = "分页参数：每页条数"),
    })
    @GetMapping("/sysStyleGet")
    public Result<TableDataInfo<BsSysConfigVO>> sysStyleGet() {
        SysDictData sysDictData = new SysDictData();
        sysDictData.setDictType(BsSysConfigConstants.SYS_STYLE);
        startPage();
        List<SysDictData> list = dictDataService.selectDictDataList(sysDictData);
        return Result.success(getDataTable(list, BsSysConfigVO.class));
    }

    @ApiOperation(value = "整理风格-配置修改", tags = {"系统配置"})
    @GetMapping("/sysStyleUpdate")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dictCode", value = "配置id"),
    })
    public Result<?> enterList(@RequestParam Long dictCode) {
        bsSysConfigService.sysStyleUpdate(dictCode);
        return Result.success();
    }

    @ApiOperation(value = "平台搜索热词-配置查询", tags = {"系统配置"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "分页参数：第几页"),
            @ApiImplicitParam(name = "pageSize", value = "分页参数：每页条数"),
    })
    @GetMapping("/sysHotWordGet")
    public Result<TableDataInfo<BsSysConfigVO>> sysHotWordGet() {
        SysDictData sysDictData = new SysDictData();
        sysDictData.setDictType(BsSysConfigConstants.SYS_HOT_WORD);
        startPage();
        List<SysDictData> list = dictDataService.selectDictDataList(sysDictData);
        return Result.success(getDataTable(list, BsSysConfigVO.class));
    }

    @ApiOperation(value = "关键词典（需屏蔽词语）-配置查询", tags = {"系统配置"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "分页参数：第几页"),
            @ApiImplicitParam(name = "pageSize", value = "分页参数：每页条数"),
    })
    @GetMapping("/sysSecretWordGet")
    public Result<TableDataInfo<BsSysConfigVO>> sysSecretWordGet() {
        SysDictData sysDictData = new SysDictData();
        sysDictData.setDictType(BsSysConfigConstants.SYS_SECRET_WORD);
        startPage();
        List<SysDictData> list = dictDataService.selectDictDataList(sysDictData);
        return Result.success(getDataTable(list, BsSysConfigVO.class));
    }

    @ApiOperation(value = "关键词典（需屏蔽词语）-配置合法校验-自测使用", tags = {"系统配置"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "msg", value = "需要校验的文本"),
    })
    @GetMapping("/allowBySysSecretWord")
    public Result<Boolean> allowBySysSecretWord(@RequestParam() String msg) {
        return Result.success(bsSysConfigService.allowBySysSecretWord(msg));
    }

    @ApiOperation(value = "关键词典（需屏蔽词语）-配置新增", tags = {"系统配置"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dictLabel", value = "配置名称"),
    })
    @GetMapping("/sysSecretWordAdd")
    public Result<?> sysSecretWordAdd(@RequestParam() String dictLabel) {
        return Result.success(bsSysConfigService.sysSecretWordAdd(dictLabel));
    }

    @ApiOperation(value = "关键词典（需屏蔽词语）-配置删除", tags = {"系统配置"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dictCode", value = "配置id:dictCode"),
    })
    @GetMapping("/sysSecretWordDel")
    public Result<?> sysSecretWordDel(@RequestParam() String dictCode) {
        return Result.success(bsSysConfigService.sysSecretWordDel(dictCode));
    }

}
